<template>
  <div id="app">
    <a-input placeholder="请输入任务" class="my_ipt" :value="inputvalue" @change="handelinputchange"/>
    <a-button type="primary" @click="additemlist">添加事项</a-button>

    <a-list bordered :dataSource="infolist" class="dt_list">
      <a-list-item slot="renderItem" slot-scope="item">
        <!-- 复选框 -->
        <a-checkbox :checked="item.done" @change="(e)=>{cbStatusChange(e,item.id)}">{{ item.info }}</a-checkbox>
        <!-- 删除链接 -->
        <a slot="actions" @click="removeitem(item.id)">删除</a>
      </a-list-item>

      <!-- footer区域 -->
      <div class="footer" slot="footer">
        <span>{{unDone}}条剩余</span>
        <a-button-group>
          <a-button :type="allstar==='all'? 'primary' : 'dafault' " @click="changfull('all')">全部</a-button>
          <a-button :type="allstar==='undone'? 'primary' : 'dafault' " @click="changfull('undone')">未完成</a-button>
          <a-button :type="allstar==='done'? 'primary' : 'dafault' " @click="changfull('done')">已完成</a-button>
        </a-button-group>
        <a @click="clearelist">清除已完成</a>
      </div>
    </a-list>
  </div>
</template>
<script>
import {mapActions,mapState,mapGetters} from 'vuex'
export default {
  name: "app",
  data() {
    return {
    
    };
  },
  created(){
this.$store.dispatch('getlist')
  },
  computed:{...mapState(['inputvalue','allstar']),
  ...mapGetters(['unDone','infolist'])},
  methods:{
    handelinputchange(e){
this.$store.commit('setinputvalue',e.target.value)
    },
    additemlist(){
      if(this.inputvalue.trim().length<=0)
      {return this.$message.error("添加内容为空！");}
        this.$store.commit('additem')
    },
    removeitem(id){
         this.$store.commit('delitem',id)
    },
    cbStatusChange(e,id){
      const parma={
        id:id,
        status:e.target.checked
      }
      this.$store.commit("changstatus",parma)
    },
    clearelist(){
      this.$store.commit('clendone')
    },
    changfull(key){
   this.$store.commit('changaoliang',key)
    }
  
  }
};
</script>
<style scoped>
#app {
  padding: 10px;
}
.my_ipt {
  width: 500px;
  margin-right: 10px;
}
.dt_list {
  width: 500px;
  margin-top: 10px;
}
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
